function [sj, sij]=LogitShareCalculation2RC(theta,delta,Data)

% LogitShareCalculation
% Syntax:   [sj sij]=LogitShareCalculation(theta,delta,Data)
%
% Inputs:
%    input1 - Non linear parameters
%    input2 - Data
%
% Outputs:
%    sij    = individual market shares
%    sj     = market shares
%
% Subfunctions: none
%

% Author: Laura Grigolon and Frank Verboven
% August 2012;

%% Unpack
prods           = Data.prods;
nmkt            = Data.nmkt;
Nnodes          = Data.Nnodes;
xvuSEG          = Data.xvuSEG;
xvuRC           = Data.xvuRC;
qweightrprods   = Data.qweightrprods;

% Market share calculation
randomcomp      = (xvuSEG.*theta(1)) + (xvuRC.*theta(2)); 
mudel           = bsxfun(@plus,delta,randomcomp);
numer1          = exp(mudel);

% use multidimensional arrays
numer1          = reshape(numer1,[prods,1,nmkt,Nnodes]);
denom1          = 1 + sum(numer1);
sij             = bsxfun(@rdivide,numer1,denom1);
sj              = sum((bsxfun(@times,sij,qweightrprods)),4);

end